package com.lt.controller.end;

import com.lt.pojo.BackendUser;
import com.lt.pojo.DevUser;
import com.lt.utils.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session =request.getSession();
        BackendUser backendUser =(BackendUser) session.getAttribute(Constants.USER_SESSION);
        DevUser devUser =(DevUser) session.getAttribute(Constants.DEV_USER_SESSION);

        if(null!=devUser){
            return true;
        }else if(null!=backendUser){
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"/403.jsp");
            return false;
        }
    }
}
